﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Motorway_Simulator.Simulator;

namespace Motorway_Simulator.Components
{
    /// <summary>
    /// AggressiveDriver has certain properties where it may change
    /// its properties more often
    /// </summary>
    [Serializable]
    public class AggressiveDriver : Driver
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AggressiveDriver"/> class.
        /// </summary>
        /// <param name="vehicle">The vehicle.</param>
        /// <param name="currentRoadUnit">The current road unit.</param>
        /// <param name="controller">The controller.</param>
                public AggressiveDriver(Vehicle vehicle, RoadUnit currentRoadUnit, SimulationController controller)
        {
            this.Vehicle = vehicle;
            vehicle.CurrentRoadUnit = currentRoadUnit;
            this.lastTimeSinceIndicated = 0;
            this.indicationTime = 0;
            this.stopRequested = false;
            this.controller = controller;
            nextIndication = 10;

        }
        /// <summary>
        /// Accelerate
        /// </summary>
        /// <returns>boolean</returns>
        public override bool Accelerate()
        {
            return vehicle.Accelerate(100);
        }

        /// <summary>
        /// Change lanes
        /// </summary>
        protected override void ChangeLanes()
        {
            RoadUnit roadUnit = controller.SearchSide(vehicle.CurrentRoadUnit,
                         SimulationController.LEFT_HAND_LANE, SimulationController.CURRENT_LANE, vehicle.CurrentRoadUnit.Direction1);
            if (roadUnit != null)
            {
                vehicle.CurrentRoadUnit = roadUnit;
            }

            else
            {
                roadUnit = controller.SearchSide(vehicle.CurrentRoadUnit,
                SimulationController.RIGHT_HAND_LANE, SimulationController.CURRENT_LANE, vehicle.CurrentRoadUnit.Direction1);
                if (roadUnit != null)
                {
                    vehicle.CurrentRoadUnit = roadUnit;
                }
            }
        }

        /// <summary>
        /// Decelerate
        /// </summary>
        /// <param name="speed"></param>
        /// <returns>True if the speed is no less than zero</returns>
        public override bool Decelerate(int speed)
        {
            if (vehicle.CurrentSpeed > 0)
            {
                if (speed > 0)
                {
                    vehicle.CurrentSpeed = speed;
                    return true;
                }
                else return false;
            }
            else
            {
                return false;
            }
        }

     
    }
}
